package com.demo.java.lang;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoField;
import java.util.Calendar;
import java.util.Date;
import java.util.concurrent.TimeUnit;

public class DateTest {
    public static void main(String[] args) {

        toMicrosecondsTest();
    }

    public static void toMicrosecondsTest() {
        String date = "2019-10-12 09:00:02";

        System.out.println(LocalDateTime.parse(date, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")).atZone(ZoneId.systemDefault()).toInstant().getEpochSecond());
        System.out.println(LocalDateTime.parse(date, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli());
        final Calendar calendar = Calendar.getInstance();
        calendar.setTime(Date.from(LocalDateTime.parse(date, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")).atZone(ZoneId.systemDefault()).toInstant()));
        System.out.println(calendar.getTimeInMillis());
        System.out.println(System.nanoTime());
    }
}
